﻿using System;
using System.Diagnostics.Contracts;

namespace CodeStream.Testing.WebAutomation
{
    /// <summary>
    /// Represents a container or a control class in the UI definition xml file.
    /// </summary>
    public class UIDefinitionField
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="UIDefinitionField"/> class.
        /// </summary>
        /// <param name="name">The name of the field.</param>
        /// <param name="typeName">Set to a string if the field is a container.</param>
        /// <param name="tag">The HTML tag describing the container or control.</param>
        /// <param name="id">The optional id used to locate the container or control in the page under test.</param>
        /// <param name="cssClass">The optional CSS class used to locate the container or control in the page under test.</param>
        /// <param name="multiple">Determines if more than one instance of the container or control is possible.</param>
        internal UIDefinitionField(string name, string typeName, string tag, string id, string cssClass, bool multiple)
        {
            Contract.Requires(!string.IsNullOrEmpty(name));
            Contract.Requires(!string.IsNullOrEmpty(tag));

            Name = name.ToIdentifier();
            IsContainer = typeName != null;
            Tag = tag;
            Id = id;
            CssClass = cssClass;
            Multiple = multiple;
            TypeName = typeName == null ? tag.ConvertToType().Name : typeName.ToIdentifier();
        }

        /// <summary>
        /// Gets the name of the field.
        /// </summary>
        public string Name { get; private set; }

        /// <summary>
        /// Gets a value indicating whether this instance is a container or a control.
        /// </summary>
        public bool IsContainer { get; private set; }

        /// <summary>
        /// Gets the HTML tag of the container.
        /// </summary>
        public string Tag { get; private set; }

        /// <summary>
        /// Gets the optional id used to identify the field in the page under test.
        /// </summary>
        public string Id { get; private set; }

        /// <summary>
        /// Gets the optional CSS class used to identify the field in the page under test.
        /// </summary>
        public string CssClass { get; private set; }

        /// <summary>
        /// Gets a value indicating whether field can contain more than a single instance of the control.
        /// </summary>
        public bool Multiple { get; private set; }

        /// <summary>
        /// Gets the name of the class that is generated for the field object.
        /// </summary>
        public string TypeName { get; private set; }               
    }
}


